import Mock from 'mockjs'

const Random = Mock.Random // Mock.Random 是一个工具类，用于生成各种随机数据

// 模拟接口数据 用户列表
let userList = []

// 初始化50条用户信息
for (let i = 0; i < 50; i++) { // 可自定义生成的个数
	let template = {
		"id": Random.guid(),
		"name": Random.cname(),
		"idCardNo": Random.id(),
		"icCardNo": Random.zip(),
		"school": Random.province() + Random.cword(2, 3) + "大学" + Random.cword(2, 3) + "学院",
		"classes": Random.cword('一二三四五六七八九十') + '班',
		"special": Random.cword(2, 3) + "系"
	}
	userList.push(template)
}

// 定义模拟接口
export default [
	{
		url: '/data/userList',
		type: 'get',

		// 定义模拟接口的返回
		response: config => {
			const { page = 1, limit = 20 } = config.body || {}
			let mockList = userList
			
			// 用filter模拟分页查询
			const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
			return {
				code: 0,
				data: {
					total: mockList.length,
					list: pageList
				}
			}
		}
	},
	{
		url: '/data/userDetail',
		type: 'get',
		response: config => {
			const { id, name, idCardNo, icCardNo } = config.body
			for (const detail of userList) {
				if (detail.id === id || (detail.name === name && detail.idCardNo === idCardNo) || (detail.name === name && detail.icCardNo === icCardNo)) {
					return {
						code: 0,
						data: detail
					}
				}
			}
		}
	},

]